//合并两个有序链表
// 1->2->3->4  1->1->2->4->5
// 1->1->1->2->2->3->4->4->5
function Node(val) {
    this.val = val;
    this.next = null;
}

var a = new Node("1");
var b = new Node("2");
var c = new Node("3");
var d = new Node("4");

var a2 = new Node("1");
var b2 = new Node("1");
var c2 = new Node("2");
var d2 = new Node("4");
var e2 = new Node("5");
a.next = b;
b.next = c;
c.next = d;

a2.next = b2;
b2.next = c2;
c2.next = d2;
d2.next = e2;

var mergeTwoList = (l1,l2) =>{
    if(l1 == null)
        return l2;
    if(l2 == null)
        return l1;
    if(l1.val <= l2.val){
        l1.next = mergeTwoList(l1.next,l2);
        return l1;
    }else{
        l2.next = mergeTwoList(l1,l2.next);
        return l2;
    }
};
var res = mergeTwoList(a,a2);
while(res){
    console.log(res.val);
    res = res.next;
}